<template>
  <div>
    <div class="tlq">
      <div class="topBars">
        <mt-button @click='goBack' class='back-btn top-img'>
          <img src="../../assets/返回.png" height="16" width="19" slot="icon">
          <!--姓名显示-->
          <span class="textstyle" v-html="getNowDialog[2]">返回</span>
        </mt-button>
        <mt-button class='tx top-img icon'>
          <img :src="getNowDialog[1]" height="40" width="40" slot="icon">
        </mt-button>
      </div>
      <div class="dialogue" v-for="item in getNowDialog[0]">
        <div class="item">
          <!--role：1 -- 表示用户自己   role：2 -- 表示回复的人（机器人）-->
          <div class="itemWrap">
            <div v-if='item.role==="1"'>
              <div class="left tx"><img :src="getNowDialog[1]" alt="" width='40' height="40"></div>
              <div class="d_content content-rebot">{{item.msg}}</div>
            </div>
            <div v-if='item.role==="2"'>
              <div class="right tx"><img src="/static/img/1.jpg" alt="" width='40' height="40"></div>
              <div class="d_content content-user">{{item.msg}}</div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <add-dialog></add-dialog>
    <router-view></router-view>
  </div>

</template>
<script>
  import addDialog from './addDialog';

  export default {
    name: 'dialogDetail',
    components: {
      'add-dialog': addDialog
    },
    computed: {
      getNowDialog() {
        let data = this.$store.state.dialogue;
        for (var i = 0; i < data.length; i++) {
          if (data[i].id == this.$route.params.id) {
            // 如果data里的id和传过来的id相等，那么久返回聊天记录的字段数组，头像已经姓名
            return [data[i].contentList, data[i].tx, data[i].name]
          }
        }
      }
    },
    methods: {
      goBack: function () {
        this.$router.push({name: 'dialogList'});
        //修改topBar状态
        this.$store.commit('setNavbar');
      }
    }
  }
</script>
<style>
  .topBars {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    background: #242f3B;
    height: 50px;
    line-height: 50px;
    z-index: 2;
  }

  .back-btn span {
    color: #fff;
    font-size: 16px;
  }

  .back-btn .textstyle {
    border-left: 1px solid #000;
    padding-left: 15px;
    margin-left: 10px;
  }

  .top-img {
    background: none;
    border: none;
    box-shadow: none;
  }

  .topBars .icon {
    margin-top: 5px;
  }

  .topBars .tx {
    float: right;
  }

  .user_tx img {
    border-radius: 50%
  }

  .tlq {
    margin-top: 60px;
    padding-bottom: 30px;
  }

  .dialogue .left {
    float: left;
  }

  .dialogue .right {
    float: right;
  }

  .dialogue .item {
    position: relative;
    min-height: 49px;
    margin-bottom: 2px;
  }

  .d_content {
    max-width: 65%;
    display: inline-block;
    border-radius: 14px;
    color: #fff;
    padding: 6px 15px 6px 7px;
    font-size: 14px;
  }

  .dialogue img {
    border-radius: 50%
  }

  .content-rebot {
    background: #3D88F6;
    margin-top: 6px;
    margin-left: 14px;

  }

  .content-user {
    background: #03AFC5;
    float: right;
    margin-top: 6px;
    margin-right: 14px;
  }

</style>
